package com.me.common.enums;

import com.me.common.constant.GlobalManager;

import java.util.Objects;

/**
 * @author jindouyun
 */
public enum YesOrNoEnum {
    /**
     * 是
     */
    YES(1, "是"),
    /**
     * 否
     */
    NO(0, "否");

    private final Integer value;

    private final String desc;

    YesOrNoEnum(Integer value, String desc) {
        this.value = value;

        this.desc = desc;
    }

    public Integer value() {
        return value;
    }

    public String desc() {
        return desc;
    }

    /**
     * 根据value获取YesOrNoEnum，null和0返回NO，其他返回YES
     *
     * @param value value
     * @return null和0返回NO，其他返回YES
     */
    public static YesOrNoEnum ofvalue(Integer value) {
        return (value == null || value == 0) ? NO : YES;
    }

    public static String tDesc(Integer val) {
        for (YesOrNoEnum en : YesOrNoEnum.values()) {
            if (Objects.equals(en.value, val)) {
                return en.desc;
            }
        }
        return GlobalManager.EMPTY;
    }
}
